package com.hurl.waguji.biz.download;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

import com.hurl.waguji.base.dao.HibernateDao;
import com.hurl.waguji.base.dataprocess.ProcessParams;

class DownloadContext {
	public static final String BO_SAVE_MODE_UPDATE = "UPDATE";
	public static final String BO_SAVE_MODE_INSERT = "INSERT";
	
	private ProcessParams params;
	private HibernateDao dao;
	private boolean stopWithError = false;
	private Throwable error;
	
	/**
	 * 存储特定的下载项需要使用的变量
	 */
	private Map<String,Object> env = new HashMap<String,Object>();
	
	private String boSaveMode = BO_SAVE_MODE_INSERT;

	public void setEnv(String key,Object value){
		env.put(key, value);
	}
	private Object getEnv(String key){
		return env.get(key);
	}
	public Date getEnvAsDate(String key){
		return (Date)getEnv(key);
	}
	public String getEnvAsString(String key){
		return (String)getEnv(key);
	}
	public void setStopWithError(Throwable error){
		stopWithError = true;
		this.error=error;
	}
	public boolean isStopWithError() {
		return stopWithError;
	}
	public Throwable getError() {
		return error;
	}
	public ProcessParams getParams(){
		return this.params;
	}
	public DownloadContext(ProcessParams params){
		this.params = params;
	}
	public void setBoSaveMode(String boSaveMode){
		this.boSaveMode=boSaveMode;
	}
	
	public String getBoSaveMode(){
		return this.boSaveMode;
	}

	public HibernateDao getDao() {
		return dao;
	}

	public void setDao(HibernateDao dao) {
		this.dao = dao;
	}

}
